/**
 * 
 */
package com.jeecms.wicool.dao.shops.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.jeecms.cms.entity.main.CmsUser;
import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.shops.AdviserDao;
import com.jeecms.wicool.entity.shops.Adviser;

/**
 * @author spring
 *
 */
@Repository
public class AdviserDaoImpl extends HibernateBaseDao<Adviser, Integer> implements
		AdviserDao {

	@Override
	public Pagination getPage(String name, String loginName, int pageNo,
			int pageSize, CmsUser user) {
		Finder f = Finder.create("select bean from Adviser bean where 1=1 ");
		if (!StringUtils.isBlank(name)) {
			f.append(" and bean.name = :name");
			f.setParam("name", name);
		}
		if (!StringUtils.isBlank(loginName)) {
			f.append(" and bean.loginName = :loginName");
			f.setParam("loginName", loginName);
		}
		f.append(" order by bean.createTime desc");
		return find(f, pageNo, pageSize);
	}

	@Override
	public Adviser findById(Integer id) {
		return get(id);
	}


	@Override
	public Adviser save(Adviser bean) {
		getSession().save(bean);
		return bean ;
	}

	@Override
	public Adviser deleteById(Integer id) {
		Adviser obj = get(id);
		if(obj != null){
			getSession().delete(obj);
		}
		return obj;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Adviser> getAll(CmsUser user) {
		Finder f = Finder
				.create("select bean from Adviser bean where 1 = 1 ");
		f.append(" order by bean.createTime desc");
		return find(f);
	}

	@Override
	protected Class<Adviser> getEntityClass() {
		return Adviser.class;
	}

}
